﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BookingSystemBLL;
using BookingSystemModel;

public partial class ChangePassword : System.Web.UI.Page
{
    user UerPwd = new user();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void SUBMIT_Click(object sender, EventArgs e)
    {
        string UserNickName = Session["UserName"].ToString();
            if (this.oldPwd.Text.Trim()=="")
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('旧密码不能为空！');</script>");
            } 
            else
            {
                if (this.oldPwd.Text != Session["Pwd"].ToString() )
                {
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('旧密码输入错误！');</script>");
                } 
                else
                {
                    if (this.newPwd.Text==""|| this.ConfirmNewPwd.Text=="")
                    {
                         Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('密码输入不能为空！');</script>");
                    } 
                    else
                    {
                        if (this.newPwd.Text!=this.ConfirmNewPwd.Text)
                        {
                             Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('两次输入的密码不一致！');</script>");
                        } 
                        else
                        {
                            string Pwd = this.newPwd.Text;
                            if (UserBLL.UpdatePwd(Pwd,UserNickName)>0)
                            {
                                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('密码修改成功！');</script>");
                                Response.Redirect("UserLogin.aspx");//重新登录
                            } 
                            else
                            {
                                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('密码修改失败！');</script>");
                            }
                        }
                    }
                }
            }
    }
    protected void RESET_Click(object sender, EventArgs e)
    {
        this.oldPwd.Text = "";
        this.newPwd.Text = "";
        this.ConfirmNewPwd.Text = "";
    }
}